<template>
	<view class="container">
		<view class="switchList">
			<view class="content">
				<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper"
				@scrolltolower="onReachBottom" @scroll="scroll" refresher-enabled="true" 
				@refresherrefresh="onRefresherrefresh" :refresher-triggered="refresherTriggered">
					<uni-list-item :title="item.title+''" :note="item.authorName+''" ellipsis="2"
						v-for="(item,index) in list" :key="index"
						:to="'/pages/photo/detail/detail?id='+ item.id + '&isRandom=true'"
						style="font-size: 30rpx;">
						<template v-slot:footer>
							<button  class="delButton" @click.stop="del(item.id)">删除</button>
						</template>
					</uni-list-item>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from "../../../utils/request.js"
	import {getUserId} from "../../../utils/auth.js"
	export default {
		data() {
			return {
				refresherTriggered: false,//当前下拉刷新状态
				statusBarHeight: 0,//状态栏高度
				id: '',//用户id
				user: {
					nickName: "陶杰",//昵称
					
				},//用户信息
				list: [
					
				],//列表内容1
				checked: false,//是否点击关注按钮,
				contentText: {contentDefault: '关注',contentFav: '已关注'},//按钮内容
				scrollTop: 0,//竖向滚动条位置
			};
		},
		onReady() {
			uni.showLoading({})
			this.getList()
		},
		methods: {
			//初始化数据
			getList() {
				request({
					url: '/articles/getListByUserId',
					data: {
						userId: getUserId()
					}
				}).then(res => {
					uni.hideLoading()
					console.log(res)
					this.list = res.data
				})
			},
			//关注按钮点击
			onClick() {
				this.checked = !this.checked
				//发送请求，
			},
			//回到上一页
			backLastPage() {
				uni.navigateBack({
					delta: 1
				})
			},
			//自定义下拉刷新被触发
			onRefresherrefresh() {
				//重新获取数据
			    console.log(1)
			},
			onReachBottom() {  
			    console.log(2)
			},  
			//删除文章
			del(id) {
				const _this = this
				uni.showModal({
					title: '提示',
					content: '是否删除文章',
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
							request({
								method: 'delete',
								url: '/articles/delete/' + id,
							}).then(res => {
								_this.getList()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
							return;
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
body {
	
}
	
.container {
	box-sizing: border-box;
	width: 100%;
	background-color: #fff;
	
}


.switchList {
	padding: 0 10rpx;
	flex-grow: 1;
	overflow-y: scroll;
	
	.switch {
		display: flex;
		justify-content: space-around;
		align-items: center;
		
		span {
			padding: 10rpx;
		}
		
	}
	
	.content {
		
		
	}
	
	.delButton {
		font-size: 13px;
	}
}


</style>
